package hanshunping.easy;

import java.util.Scanner;

/**
 * @author ：蔡博
 * @description：TODO
 * @date ：2022/5/1 16:53
 */

/**
 * @Author 蔡博
 * @Description 使用异常处理机制使用户输入整数，不满足则重新输入
 * @Date 12:11 2022/5/2
 * @Param
 * @return
 **/
public class ExceptionHandle {
    public static void main(String[] args) throws Exception {
        boolean t = true;
        Scanner ms = new Scanner(System.in);
        while (t) {
            System.out.println("请输入整数");
            try {
                int t1 = Integer.parseInt(ms.next());
                System.out.println("整数为：" + t1);
                t = false;
            } catch (Exception e) {
                System.out.println("这不是整数");
            }
        }
    }
}





class Register {
    public static void main(String[] args) throws Exception {
        myException DD =new myException();
        System.out.println("请输入名字");
        Scanner a = new Scanner(System.in);
        String name = a.next();
        Register aa = new Register();
        try {
            aa.userRe(name);
            System.out.println("ee");
        } catch (myException ed) {
            System.out.println(ed.getMessage());

        } finally {
            System.out.println("niu");
        }
        System.out.println("haha");
        aa.test();
    }

    void userRe(String name) throws myException {
        myException DD =new myException();
        if (!(name.length() <= 5))
            throw DD;
    }
    void test() throws myException {
        throw new myException();
    }
}


class myException extends Exception{
    public myException(){
        super("自定义的");
    }
}

class ExceptionTest{
    public static void main(String[] args) throws Exception{
        new ExceptionTest().j();
        System.out.println("haha");
    }
    void t() {
        ExceptionTest a = null;
        a.q();
    }
    void j() throws Exception {
        try{
        this.t();}
        catch (NullPointerException e){
            System.out.println("抓到t");
        }
    }
    void q(){

    }
}